package com.qingke.easyjava.hibernate;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.criterion.DetachedCriteria;

import com.qingke.easyjava.hibernate.bean.Student;

public class CriteriaDemo {
	public static void main(String[] args) {
		try{
			SessionFactory sf =new Configuration().configure().buildSessionFactory();
			Session session =sf.openSession();
			
			Criteria critera =session.createCriteria(Student.class);
			
			List students =critera.list();
			
			for(Object obj:students){
				System.out.println(obj);
			}
			
			DetachedCriteria c =DetachedCriteria.forClass(Student.class);
			Criteria cc=c.getExecutableCriteria(session);
			List stds=cc.list();

			for(Object obj:stds){
				System.out.println(obj);
			}
		}catch(HibernateException e){
			e.printStackTrace();
		}
	}
}
